﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace MEF_Import_And_Export
{
    /// <summary>
    /// App.xaml 的交互逻辑
    /// </summary>
    public partial class App : Application
    {
        [Import]
        public Window MainWindow { get; set; }

        public App()
        {
            this.Startup += App_Startup;
        }

        void App_Startup(object sender, StartupEventArgs e)
        {
            int i = 2;
            switch (i)
            {
                case 0:
                    var catalog = new AssemblyCatalog(typeof(App).Assembly);
                    //var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
                    var container = new CompositionContainer(catalog);
                    container.ComposeParts(this);

                    this.MainWindow = container.GetExportedValue<Window>(); 
                    MainWindow.Show();
                    break;
                case 1:
                    var catalog1 = new AssemblyCatalog(typeof(App).Assembly);
                    //var catalog = new AssemblyCatalog(System.Reflection.Assembly.GetExecutingAssembly());
                    var container1 = new CompositionContainer(catalog1);
                    container1.ComposeParts(this);

                    base.MainWindow = MainWindow;
                    MainWindow.Show();
                    break;
                case 2:
                    var starter = new CompositionStarter<object>();
                    starter.Start();
                    break;
                default:
                    break;
            }


        }
    }
}
